import json


class Send:
    def send_login(self,session,name,password):

        url="http://localhost:90/login/verifyLogin"
        param={
            "username":name,
            "password":password
        }
        resp=session.get(url=url,params=param)

        resp.encoding="utf-8"

        code = resp.status_code

        body = resp.text

        body = json.loads(body)

        print(code,body,type(body),body.get("code"))

        return{"code":code,"body":body}

    def send_register(self,session,name,password):
        url="http://localhost:90/login/register"
        param={
            "username":name,
            "password":password
        }
        resp=session.post(url=url,data=param)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return {"code":code,"body":body}

    def send_add(self,session,cardbank,cardtype,cardnum):
        url="http://localhost:90/user/addBankCard"
        param={
            "cardbank":cardbank,
            "type":cardtype,
            "cardnum":cardnum
        }
        resp=session.post(url=url,data=param)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return{"code":code,"body":body}

    def send_update(self,session,id,cardbank,cardtype,cardnum):
        url="http://localhost:90/user/updateBankCard"+"/"+str(id)

        param={
            "cardbank":cardbank,
            "type": cardtype,
            "cardnum": cardnum
        }
        resp=session.put(url=url,params=param)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return{"code":code,"body":body}

    def send_delete(self,session,id):
        url="http://localhost:90/user/deleteBankCard"+"/"+str(id)

        resp=session.delete(url=url)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return {"code":code,"body":body}

    def send_updatePwd(self,session,id,oldpwd,newpwd):
        url="http://localhost:90/user/updatePwd"

        param={
            "id":id,
            "oldpwd":oldpwd,
            "newpwd":newpwd
        }
        resp=session.put(url=url,params=param)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return{"code":code,"body":body}

    def send_buyc(self,session,cid,uid,pwd):
        url="http://localhost:90/user/userBuyChangeMoney"

        param={
            "changeMoneyId":cid,
            "userId":uid,
            "passWord":pwd
        }
        resp=session.post(url=url,data=param)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return {"code":code,"body":body}

    def send_buyt(self,session,tid,uid,pwd):
        url="http://localhost:90/user/buyTermFinancial"
        param={
            "termFinancialId":tid,
            "userId":uid,
            "passWord":pwd
        }
        resp=session.post(url=url,data=param)

        resp.encoding="utf-8"

        code=resp.status_code

        body=resp.text

        body=json.loads(body)

        print(code,body,type(body),body["code"])

        return {"code":code,"body":body}

    def send_buyf(self, session, fid, uid, pwd):
        url = "http://localhost:90/user/buyFundProduct"
        param = {
            "fundProductId": fid,
            "userId": uid,
            "passWord": pwd
        }
        resp = session.post(url=url, data=param)

        resp.encoding = "utf-8"

        code = resp.status_code

        body = resp.text

        body = json.loads(body)

        print(code, body, type(body), body["code"])

        return {"code": code, "body": body}

    def send_loan(self, session, amount, term, rate):
        url = "http://localhost:90/user/applyLoan"
        param = {
            "amount": amount,
            "term": term,
            "rate": rate
        }
        resp = session.post(url=url, data=param)

        resp.encoding = "utf-8"

        code = resp.status_code

        body = resp.text

        body = json.loads(body)

        print(code, body, type(body), body["code"])

        return {"code": code, "body": body}

